<?php
/**
 *    This file is NOT part of "Liberty Gaming NQ Stats Analyzer".
 *
 *    This file is an add-on for "Liberty Gaming NQ Stats Analyzer" to make Award Dectection Work.
 *    There are also significant changes in other files to claim all requierd data.
 *    This is working with a diffrent setup for MySQL as I use Multi-Dimension Array's
 *    This is designed by Johan (Johnnei) for Endless-Gaming.
 */


/**
 * Class PCPIN_GameClientAwards
 * Manage Awards gained during game session.
 * @author Johan (Johnnei)
 * @copyright No Copyrights
 */
class PCPIN_GameClientAwards extends PCPIN_Session {
	
  /**
   * Game ID
   * @var int
   */
  var $game_id=0;

  /**
   * Awards gained by parser.class.php
   * "jackTheRipper" => array("GUID" => -1, "kills" => -1),	//Jack The Ripper Award
   * "grenadier" => array("GUID" => -1, "kills" => -1),		//Grenadier Award
   * "rifleNader" => array("GUID" => -1, "kills" => -1),	//Riflenade Master
   * "drOverdose" => array("GUID" => -1, "kills" => -1),	//Dr. Overdose Award
   * "accuracy" => array("GUID" => -1, "kills" => -1),		//Highest Overall Accuracy
   * "artySpammer" => array("GUID" => -1, "kills" => -1),	//Artillary Spammer
   * "fragger" => array("GUID" => -1, "kills" => -1),		//Highest Fragger
   * "purpleHeart" => array("GUID" => -1, "kills" => -1),	//Purple Heart Award
   * "mostHeadshots" => array("GUID" => -1, "kills" => -1) 	//Most Headshots
   * @var array
   */
  var $awards=null;
  
  /**
   * Constructor
   * @param   object  &$sessionhandler  Session handler
   */
  function PCPIN_GameClientAwards(&$sessionhandler) {
    // Init object
    $this->_s_init($sessionhandler, $this);
  }
  
  function getTableFields()
  {
	  return "`game_id`, `mostHeadshots`, `accuracy`, `jackTheRipper`, `bestGrenadier` , `riflenadeMaster`, `artillerySpammer`, `drOverdose`, `bestMedic`, `bestEngineer`, `bestSoldier`, `bestCovertOps`, `bestFieldOps`, `mostHeadshotsKills`, `accuracyKills`, `jackTheRipperKills`, `bestGrenadierKills`, `riflenadeMasterKills`, `artillerySpammerKills`, `drOverdoseKills`, `bestMedicKills`, `bestEngineerKills`, `bestSoldierKills`, `bestCovertOpsKills`, `bestFieldOpsKills`";
  }
  
  function getTableValues()
  {
	  return 
	  $this->game_id.", '".
	  //GUIDS
	 $this->awards['mostHeadshots']['GUID']."','".$this->awards['accuracy']['GUID']."','".$this->awards['jackTheRipper']['GUID']."','".
	  $this->awards['grenadier']['GUID']."', '".$this->awards['rifleNader']['GUID']."', '".$this->awards['artySpammer']['GUID']."', '".
	  $this->awards['drOverdose']['GUID']."','".$this->awards['bestMedic']['GUID']."','".$this->awards['bestEngineer']['GUID']."', '" .
	$this->awards['bestSoldier']['GUID']."','".$this->awards['bestCovertops']['GUID']."','".$this->awards['bestFieldops']['GUID']."',".
	  //Values of The Award Winner
	  $this->awards['mostHeadshots']['kills'].", ".$this->awards['accuracy']['kills'].",".$this->awards['jackTheRipper']['kills'].", ".
	  $this->awards['grenadier']['kills'].", ".$this->awards['rifleNader']['kills'].", ".$this->awards['artySpammer']['kills'].", ".
	  $this->awards['drOverdose']['kills'].",".$this->awards['bestMedic']['kills'].",".$this->awards['bestEngineer']['kills'].", " .
	  $this->awards['bestSoldier']['kills'].", ".$this->awards['bestCovertops']['kills'].",".$this->awards['bestFieldops']['kills'];
  }
  
  /**
   * Store new record
   * @param   int       $game_id        Game ID
   * @param   array		$awards			All Awards of the Session
   */
  function addRecord($game_id, $awards) {
    $this->game_id=$game_id;
	$this->awards=$awards;
	//INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
    $query = "INSERT INTO `ets_gameclientawards` (".$this->getTableFields().") VALUES (".$this->getTableValues().");";
	  $q = mysql_query($query);
	  if(!$q)
	  	print("<b>Invalid Awards Send</b>: ".mysql_error()."<br/>");
  }
  
 /**
  * Get GUID and Value of specific award
  * @param	string		$award		Award Name as in Database
  * @param	int			$g_id		Game ID
  * return array
  */
  function getAwardArray($award, $g_id)
  {
	  $query = "SELECT `".$award."`,`".$award."Kills` FROM `ets_gameclientawards` WHERE `game_id` = ".$g_id.";";
	  $q = mysql_query($query);
	  if(!$q)
	  	print("<b>Invalid Awards Recieved</b>: ".mysql_error()."<br/>");
	  $arr;
	  while($awards = mysql_fetch_array($q))
	  {
		$cn=new PCPIN_ClientName($this);
        if ($cn->_db_getList('name, name_txt', 'guid = '.$awards[0], 'last_used = y', 1)) {
          $arr['GUID']=$cn->_db_list[0]['name'];
          $cn->_db_freeList();
        }
		else if($awards[0] == '-1')
		{
			$arr['GUID']='-1';
		}
		  $arr['kills'] = $awards[1];
		  return $arr;
	  }
  }

}?>